package com.waidi.clothespad.fragment;

import android.app.Fragment;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.handmark.pulltorefresh.library.ILoadingLayout;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.waidi.clothespad.R;
import com.waidi.clothespad.adapter.ItemVideoListAdapter;
import com.waidi.clothespad.adapter.ListVideoViewData;
import com.waidi.clothespad.adapter.ListViewVideoAdapter;
import com.waidi.clothespad.adapter.ListviewData;
import com.waidi.clothespad.common.Config;
import com.waidi.clothespad.common.DownloadUtils;
import com.waidi.clothespad.common.DpsOrderInfo;
import com.waidi.clothespad.common.Ftp;
import com.waidi.clothespad.common.Ftp.DeleteFileProgressListener;
import com.waidi.clothespad.common.Ftp.DownLoadProgressListener;
import com.waidi.clothespad.common.Ftp.UploadProgressListener;
import com.waidi.clothespad.common.HttpDownFile;
import com.waidi.clothespad.common.MessageToUi;
import com.waidi.clothespad.common.MyToast;
import com.waidi.clothespad.ui.LvAdapter;
import com.waidi.clothespad.ui.MyListView;
import com.waidi.clothespad.websocket.MyWebsocketClient;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.security.acl.LastOwnerException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2017/4/26.
 */

public class FragGongyishipin extends Fragment {
    private static final String TAG = "FragGongyishipin";
    @BindView(R.id.lv_video_list)
    ListView lvVideoList;

    @BindView(R.id.video_cache_clear)
    TextView Video_cache_clear;


    @BindView(R.id.pulltoresfreshlistview)
    PullToRefreshListView pulltorefreshVideoList;

    @BindView(R.id.vv_video)
    VideoView vvVideo;
    Unbinder unbinder;
    private ILoadingLayout startLabels;
    private View view;
    public Context context;
    private  String  VideoPath = null;
    private String urlStr = null;
    private String loclfile =null;
    private HashMap<String,Video> videolist = new HashMap<String,Video>();
    private DownloadUtils downloadUtils;
    private LvAdapter adapter0 = null;
    private ListViewVideoAdapter adapter = null;
    private List<ListVideoViewData> mData = null;
    private List<ListVideoViewData> mDataCache = null;

    private List<String> list;
    public  GongYIShiPinHandler handler;
    private boolean onDetach = false;
    private static  int errFlag = 0;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        view = inflater.inflate(R.layout.frag_gongyishipin, container, false);
        unbinder = ButterKnife.bind(this, view);
        onDetach = false;

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        context = getActivity();
        handler = new GongYIShiPinHandler();
        initParam();
        initElem();
        onDetach = false;
       // timer.schedule(task,0,3000); //定时更新listview，哈希适配器存放于内存

    }
    @Override
    public void onStart() {
        super.onStart();

    }

    @Override
    public void onStop() {
        super.onStop();
        //timer.cancel();
    }

    public void initParam() {
/*        File file = new File(Environment.getExternalStorageDirectory() + "/video/");
        VideoPath = file.toString();*/
        VideoPath = Config.videopath;
        Log.i(TAG,VideoPath);

        String mm = Config.getAvailableExternalMemorySize(context);
        Log.i(TAG,mm);

/*        urlStr = "http://192.168.1.249/1.mp4";
        loclfile = "/1.mp4";
        videolist.put("0",new Video("/0.mp4","http://192.168.1.249/工艺视频0.mp4",null));
        videolist.put("1",new Video("/1.mp4","http://192.168.1.249/1.mp4",null));
        videolist.put("2",new Video("/2.mp4","http://192.168.1.249/2.mp4",null));
        videolist.put("3",new Video("/3.mp4","http://192.168.1.249/3.mp4",null));
        videolist.put("4",new Video("/4.mp4","http://192.168.1.249/4.mp4",null));
        videolist.put("5",new Video("/5.mp4","http://192.168.1.249/5.mp4",null));*/
    }

    public void initElem() {
        /*       final ItemVideoListAdapter adapter = new ItemVideoListAdapter(context,getDatas(),R.layout.item_video_list);*/
        mDataCache = new LinkedList<ListVideoViewData>();
        mData = new LinkedList<ListVideoViewData>();
/*        ListVideoViewData list0 = new ListVideoViewData(R.mipmap.ic_list_item_play, "视频01", "http://192.168.100.200/1.mp4", 0);
        ListVideoViewData list1 = new ListVideoViewData(R.mipmap.ic_list_item_play, "视频02", "http://192.168.100.200/2.mp4", 0);

        ListVideoViewData list2 = new ListVideoViewData(R.mipmap.ic_list_item_play, "视频03", "http://192.168.100.200/2.mp4", 0);
        ListVideoViewData list3 = new ListVideoViewData(R.mipmap.ic_list_item_play, "视频04", "http://192.168.100.200/2.mp4", 0);


        mData.add(list0);
        mData.add(list1);

        mData.add(list2);
        mData.add(list3);*/

        try
        {
            File path = new File(Config.videopath);
            File[] files = path.listFiles();// 读取文件夹下文件
            int len  = files.length;

            for(int i = 0;i<len;i++)
            {
                ListVideoViewData tmp = new ListVideoViewData();
                tmp.setImgId(R.mipmap.ic_list_item_play);
                tmp.setName(files[i].getName());
                tmp.setFileSize((int)files[i].length());
                tmp.setUrl("");
                mData.add(tmp);
            }

            Video_cache_clear.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    File dirFile = new File(Config.videopath);

                    File[] files = dirFile.listFiles();
                    for (int i = 0; i < files.length; i++) {
                        File f = files[i];
                        f.delete();
                    }
                    MyToast.showToast(context,"clear success");
                    mData.clear();
                    adapter = new ListViewVideoAdapter((LinkedList<ListVideoViewData>) mData, context);
                    pulltorefreshVideoList.setAdapter(adapter);
                    adapter.notifyDataSetChanged();
                }
            });


        }catch (Exception e)
        {

        }





        adapter = new ListViewVideoAdapter((LinkedList<ListVideoViewData>) mData, context);
        // lvVideoList.setAdapter(adapter);


        pulltorefreshVideoList.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
        pulltorefreshVideoList.setAdapter(adapter);
        adapter.notifyDataSetChanged();

        startLabels = pulltorefreshVideoList.getLoadingLayoutProxy(true, false);
        startLabels.setPullLabel("下拉刷新...");
        startLabels.setRefreshingLabel("正在刷新...");
        startLabels.setReleaseLabel("放开刷新...");

        pulltorefreshVideoList.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            //下拉刷新的时候调用的方法....请求第一页的数据,清空之前的数据,然后再添加设置适配器
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                //下拉刷新....请求第一页的数据,清空之前的数据,然后再添加设置适配器
                //getReshData();

                new FragGongyishipin.GetDataTask().execute();
            }


            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                //getDataFrom();
            }
        });


        pulltorefreshVideoList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long l) {

                try
                {
                    Log.i(TAG, "position:" + Integer.toString(position));
                    position = position - 1;
                    adapter.setSelectPosition(position);
                    errFlag = -1;

                    String url = adapter.getCurrentPositiomVideoUrl();
                    Log.i(TAG, "video url:" + url);
                    String name = adapter.getCurrentPositiomVideoFileName();
                    if (name.length() == 0) {
                        MyToast.showToast(context, "工艺视频名称为空！");
                        return;
                    }

                    Uri uri = Uri.parse(url); //
                    String videofile = null;

                    videofile = VideoPath + "/" + adapter.getCurrentPositiomVideoFileName();
                    Log.i(TAG, videofile);

                    //Log.i(TAG, uri.toString());

                    vvVideo.setMediaController(new MediaController(context));
                    File FileCache = new File(videofile);
                    Long fileSize = adapter.getCurrentPositiomVideoFileSize();
                    if (FileCache.exists() && FileCache.length() == fileSize) //本地缓存视频存在
                    {
                        vvVideo.setVideoPath(videofile);//播放本地视频
                    } else {
                        vvVideo.setVideoURI(uri); ////播放网络视频
                        urlStr = url;
                        loclfile = name;
                        HttpDownLoad();
                    }
                } catch (Exception io) {
                    Log.e(TAG, "IO ERROR！");
                    io.printStackTrace();
                }
                try {
                    vvVideo.start();
                    vvVideo.requestFocus();
                } catch (Exception ex) {
                    Log.e(TAG, "IO ERROR！！！！");
                    ex.printStackTrace();
                }
            }
        });


/*        lvVideoList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){

            @Override
            public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                                    int position, long id){

                Config.videoMap.remove(position);
                final ItemVideoListAdapter adapter = new ItemVideoListAdapter(context,getDatas(),R.layout.item_video_list);
                lvVideoList.setAdapter(adapter);
                return false;
            }

        });*/


        vvVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                try
                {
                    mp.start();
                    Log.i(TAG, "准备完毕,可以播放了");
                    /*mp.setLooping(true);*/
                    Toast.makeText(context, "准备开始播放。。", Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });
        ;

        vvVideo.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                // 播放结束后的动作
                //mp.stop();
                try
                {
                    mp.pause();
                    //mp.release();
                    Toast.makeText(context, "播放结束", Toast.LENGTH_LONG).show();

                } catch (Exception e) {

                }

            }
        });

/*        vvVideo.setOnInfoListener(new MediaPlayer.OnInfoListener() {
            @Override
            public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
                if(what==MediaPlayer.MEDIA_INFO_BUFFERING_START ){
                    Toast.makeText(context,
                            "正在缓冲",
                            Toast.LENGTH_LONG).show();
                }
                return false;
            }
        });*/

/*        vvVideo.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                resetVideoView(!mediaPlayer.isPlaying());
                return false;
            }
        });*/


        vvVideo.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                //Toast.makeText(context, "播放错误", Toast.LENGTH_LONG).show();
                //播放异常，则停止播放，防止弹窗使界面阻塞
                try
                {
                    Log.e(TAG, "错误类型:" + Integer.toString(what) + "#" + Integer.toString(extra));

                    mp.stop();
                    // mp.release();

                    //return true;
                    if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
                        //媒体服务器挂掉了。此时，程序必须释放MediaPlayer 对象，并重新new 一个新的。
                        if (errFlag != what) {
                            Toast.makeText(context, "媒体服务器错误", Toast.LENGTH_SHORT).show();
                            errFlag = what;
                        }
                    } else if (what == MediaPlayer.MEDIA_ERROR_IO) {
                        //媒体服务器挂掉了。此时，程序必须释放MediaPlayer 对象，并重新new 一个新的。
                        if (errFlag != what) {
                            Toast.makeText(context, "网络不可访问错误", Toast.LENGTH_SHORT).show();
                            errFlag = what;
                        }
                    } else if (what == -38) {
                        //媒体服务器挂掉了。此时，程序必须释放MediaPlayer 对象，并重新new 一个新的。


                        if (errFlag != what) {
                            Toast.makeText(context, "网络不可访问错误", Toast.LENGTH_SHORT).show();
                            errFlag = what;
                        }

                    } else if (what == MediaPlayer.MEDIA_ERROR_UNKNOWN) {
                        if (errFlag != what) {
                            errFlag = what;
                        } else
                            return false;

                        if (extra == MediaPlayer.MEDIA_ERROR_IO) {
                            //文件不存在或错误，或网络不可访问错误
                            Toast.makeText(context,
                                    "网络文件错误",
                                    Toast.LENGTH_SHORT).show();
                        } else if (extra == MediaPlayer.MEDIA_ERROR_TIMED_OUT) {
                            //超时

                            Toast.makeText(context, "网络超时", Toast.LENGTH_SHORT).show();

                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return true;
            }
        });

        //缓冲监听
        vvVideo.setOnInfoListener(new MediaPlayer.OnInfoListener() {
            public boolean onInfo(MediaPlayer mp, int what, int extra) {
                try
                {
                    if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
                        Toast.makeText(context, "正在缓冲", Toast.LENGTH_LONG).show();
                    } else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
                        //此接口每次回调完START就回调END,若不加上判断就会出现缓冲图标一闪一闪的卡顿现象
                        if (mp.isPlaying()) {
                            Toast.makeText(context, "缓冲结束", Toast.LENGTH_LONG).show();
                            vvVideo.setVisibility(View.VISIBLE);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return true;
            }
        });

        try
        {
            Config A = new Config(context);
            Config.DpsInterface dpsInterface = A.new DpsInterface(Config.devConfig.web_addr);
            if (DpsOrderInfo.styNum.length() == 0) {
                // MyToast.showToast(context,"当前终端上的款号为空,无法获取对应款号的视频列表!");
                //return;
            }
            String styleNum = URLEncoder.encode(DpsOrderInfo.styNum, "utf-8");
            String url = dpsInterface.videlist + styleNum;
            getVideoListInfoRequest(url);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }


    private  void DownLoadFile()
    {

        new Thread(new Runnable() {
            @Override
            public void run() {
                // 下载
                try {
                    Ftp ss = new Ftp();
                   // ss.openConnect();
                   // ss.test();
                    //单文件下载
                    ss.downloadSingleFile("2.mp4", VideoPath,"/2.mp4",new DownLoadProgressListener(){
                        @Override
                        public void onDownLoadProgress(String currentStep, long downProcess, File file) {
                            Log.d(TAG, currentStep);
                            if(currentStep.equals(Ftp.FTP_DOWN_SUCCESS)){
                                Log.d(TAG, "-----xiazai--successful");
                            } else if(currentStep.equals(Ftp.FTP_DOWN_LOADING)){
                                Log.d(TAG, "-----xiazai---"+downProcess + "%");
                            }
                        }

                    });

                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }).start();
    }

    public void HttpDownLoad() {
       // final String path = Environment.getExternalStorageDirectory().getPath() + "/AAAAImg/";
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(20000);//等待视频缓冲20s
                    HttpDownFile dd = new HttpDownFile();
                    dd.downLoadFromUrl(urlStr, loclfile,VideoPath);
                    //dd.BreakpointDownload(urlStr, loclfile,VideoPath);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }
    private List<String> getDatas()
    {
        //List<String> list = new ArrayList<String>();
        list = new ArrayList<String>();

        Config A = new Config(context);
        Config.Video tmp = A.new Video("测试0.mp4","http://192.168.100.10/1.mp4","1000","1000");


        Config.videoMap.put("0",tmp);
        Config.Video tmp1 = A.new Video("测试1.mp4","http://192.168.100.40/2.mp4","1000","1000");

        Config.videoMap.put("1",tmp1);
        Config.Video tmp2 = A.new Video("测试2.mp4","http://192.168.100.40/3.mp4","1000","1000");


        Config.videoMap.put("2",tmp2);

        if(Config.videoMap.size()!=0)
            list.clear();
        for (int i=0;i<Config.videoMap.size();i++)
        {
            list.add(Config.videoMap.get(Integer.toString(i)).localfile);
        }

        return list;
    }


    private List<ListviewData> getDataVideos(){
        //List<String> list = new ArrayList<String>();
        List<ListviewData> mData0 = new LinkedList<ListviewData>();

        Config A = new Config(context);
        Config.Video tmp = A.new Video("测试0.mp4","http://192.168.100.200/1.mp4","1000","1000");


        Config.videoMap.put("0",tmp);
        Config.Video tmp1 = A.new Video("测试1.mp4","http://192.168.100.200/2.mp4","1000","1000");

        Config.videoMap.put("1",tmp1);
        Config.Video tmp2 = A.new Video("测试2.mp4","http://192.168.100.200/3.mp4","1000","1000");

        Config.videoMap.put("2",tmp2);
        if(Config.videoMap.size()!=0)
            mData.clear();

        return mData0;
    }

    @Override
    public void onDestroyView()
    {
        super.onDestroyView();
        onDetach = true;
        Log.i(TAG,"onDestroy ....onDetach. is true..");
        unbinder.unbind();
    }

    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
        @Override
        public void run()
        {

            if(onDetach== false)
            {
                Message message = new Message();
                message.arg1 = 1;
                handler.sendMessage(message);
            }
        }
    };


    //自定义handler类
    class GongYIShiPinHandler extends Handler {
        @Override
        //接收别的线程的信息并处理
        public void handleMessage(Message msg) {
            Log.i("GongYIShiPinHandler",Integer.toString(msg.arg1));
            try
            {
                if(onDetach == true)
                    return;

                switch (msg.arg1)
                {
                    case 1:
                    mData = new LinkedList<ListVideoViewData>();
                    mData = mDataCache;
                    Log.i(TAG,"视频列表信息更新了"+mData.size());

                    adapter = new ListViewVideoAdapter((LinkedList<ListVideoViewData>) mData,context);
                    pulltorefreshVideoList.setAdapter(adapter);
                    adapter.notifyDataSetChanged();
                    pulltorefreshVideoList.onRefreshComplete();
                    MyToast.showToast(context,"视频列表信息更新了"+mData.size()+"条");

                    break;
                    case 2:
                        Bundle bundle1 = msg.getData();
                        break;
                    case 3:
                        break;
                    case 23:
                    {
                        Bundle bundle23=msg.getData();
                        String info = bundle23.getString("exception");
                        MyToast.showToast(context,info);
                    }
                        break;

                    default:
                        break;
                }
            }catch (Exception e)
            {
                e.printStackTrace();
                MyToast.showToast(context,e.toString());
            }
        }
    }

    private void getVideoListInfoRequest(final String url)
    {
        httpGetVideoList thread = new httpGetVideoList(handler,context,url);
        thread.start();
    }

    public class httpGetVideoList extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;

        public httpGetVideoList(Handler handlerin, Context contextin, String url) {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;
        }
        public void run()
        {
            Message msg1;
            String result = "";
            try
            {
                HttpClient httpCient = new DefaultHttpClient();
                httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,4000);//连接时间
                httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间
                HttpGet httpGet = new HttpGet(Url);
                int code = -1;

                Log.i(TAG, Url);
                HttpResponse response = httpCient.execute(httpGet);
                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "get call reponse code: "+Integer.toString(code));
                if (response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity = response.getEntity();
                    result = EntityUtils.toString(entity, HTTP.UTF_8);
                    Log.i(TAG, result);
                    try {

                        JSONObject jsonObj = new JSONObject(result);
                        if (jsonObj == null)
                            return;

                        if(jsonObj.has("error")==true)
                        {
                            Log.i(TAG,"获取工艺视频错误！！");
                            JSONObject error =  jsonObj.optJSONObject("error");
                            String message = error.optString("message");
                            String s = "获取工艺视频错误："+message;
                            new MessageToUi().send(23,"exception",s,handler0);
                        }
                        else
                        {
                            if(jsonObj.has("data")==true) {
                                JSONArray array0 = jsonObj.optJSONArray("data");
                                mDataCache.clear();
                                Log.i(TAG, "工艺视频列表刷新成功！"+array0.length());
                                for(int i=0;i<array0.length();i++)
                                {
                                    ListVideoViewData tmp = new ListVideoViewData();
                                    JSONObject obj = array0.optJSONObject(i);
                                    String name = obj.optString("name");
                                    String url = obj.optString("url");
                                    int size = obj.optInt("size");
                                    tmp.setImgId(R.mipmap.ic_list_item_play);
                                    tmp.setName(name);
                                    tmp.setFileSize(size);
                                    tmp.setUrl(url);
                                    mDataCache.add(tmp);
                                }
                                new MessageToUi().send(1,"info","获取工艺视频列表信息成功",handler0);
                                /*  刷新界面*/
/*                                File dpsProuductIndotxt = new File(Config.dpsProuductIndotxt);
                                OutputStream os = new FileOutputStream(dpsProuductIndotxt);
                                byte b[] = jsonObj.toString().getBytes("UTF-8");
                                os.write(b);
                                os.close();*/
                            }

                        }
                    }
                    catch (JSONException e)
                    {
                        e.printStackTrace();
                        new MessageToUi().send(23,"exception",e.toString(),handler0);
                    }
                }
                else
                {
                    Log.i(TAG,"服务端返回："+Integer.toString(code));
                    new MessageToUi().send(23,"exception","服务端返回："+Integer.toString(code),handler0);

                }
            }catch (Exception e)
            {

                Log.e(TAG, "HTTP request err......");
                e.printStackTrace();
                new MessageToUi().send(23,"exception",e.toString(),handler0);
            }

        }

    }

    public final  class videolist
    {
        public String name;
        public String url;
        public int filesize;

        public videolist()
        {
            this.name ="" ;
            this.url ="" ;
            this.filesize = 0;
        }
    }

    public final class Video
    {
        public String localfile;
        public  String urlStl;
        public String md5;
        public Video(String localfilename,String urlStlname,String md5)
        {
            this.localfile = localfilename;
            this.urlStl = urlStlname;
            this.md5 = md5;
        }
    }

    private class GetDataTask extends AsyncTask<Void, Void, String[]> {

        @Override
        protected String[] doInBackground(Void... params) {
            // Simulates a background job.
            try
            {

                Config A = new Config(context);
                Config.DpsInterface dpsInterface = A.new DpsInterface(Config.devConfig.web_addr);
                String styleNum = URLEncoder.encode(DpsOrderInfo.styNum, "utf-8");
                String url =dpsInterface.videlist+styleNum;
                getVideoListInfoRequest(url);
                Thread.sleep(2000);

            } catch (Exception e)
            {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String[] result) {

            pulltorefreshVideoList.onRefreshComplete();
            super.onPostExecute(result);
        }
    }
}
